<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${projectConfig.basePackage}.${config.model}.mapper.gen.${config.objectName}Mapper" >
  <resultMap id="BaseResultMap" type="${projectConfig.beanPackage}.${config.model}.bean.po.gen.${config.objectName}" >
  <#list pks as prop>
    <id column="<#if projectConfig.columnType=="upper">${prop.alias?upper_case}<#elseif projectConfig.columnType=="lower">${prop.alias?lower_case}<#else>${prop.alias}</#if>" property="${prop.alias}" jdbcType="${prop.jdbcType}" />
  </#list>
  <#list columns as prop>
    <result column="<#if projectConfig.columnType=="upper">${prop.alias?upper_case}<#elseif projectConfig.columnType=="lower">${prop.alias?lower_case}<#else>${prop.alias}</#if>" property="${prop.alias}" jdbcType="${prop.jdbcType}" />
  </#list>
  </resultMap>
    <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${"$"}{criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${"$"}{criterion.condition} ${"#"}{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${"$"}{criterion.condition} ${"#"}{criterion.value} and ${"#"}{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${"$"}{criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    ${"#"}{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${"$"}{criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${"$"}{criterion.condition} ${"#"}{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${"$"}{criterion.condition} ${"#"}{criterion.value} and ${"#"}{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${"$"}{criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    ${"#"}{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
<#list pks as prop>
        ${prop.name} as ${prop.alias},
</#list>
<#list columns as prop>
     <#if !prop_has_next>
        ${prop.name} as ${prop.alias}
    <#else>
        ${prop.name} as ${prop.alias},
	</#if>
</#list>
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="${projectConfig.beanPackage}.${config.model}.bean.po.gen.${config.objectName}Example" >
    <#if projectConfig.dbType == "oralce">
    <if test="limitStart != -1" >
      SELECT * FROM(
		SELECT A.*, ROWNUM RN
		FROM (
    </if>
    <#elseif projectConfig.dbType == "mysql">
    <#elseif projectConfig.dbType == "postgresql">
    </#if>
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from ${config.tableName}
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${"$"}{orderByClause}
    </if>
    <#if projectConfig.dbType == "oralce">
    <if test="limitStart != -1" >
      ) A  WHERE ROWNUM &lt;= ${"#"}{limitStart} + ${"#"}{limitOffset} ) WHERE RN &gt; ${"#"}{limitStart}
    </if>
   <#elseif projectConfig.dbType == "mysql">
    <if test="limitStart != -1" >
      limit ${"#"}{limitStart} , ${"#"}{limitOffset}
    </if>
   <#elseif projectConfig.dbType == "postgresql">
    <if test="limitStart != -1" >
      limit ${"#"}{limitOffset} offset ${"#"}{limitStart}
    </if>
   </#if>
  </select>
<#if (pks?size>0)>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="map" >
    select 
    <include refid="Base_Column_List" />
    from ${config.tableName}
    where
    <trim prefix="(" suffix=")" suffixOverrides="," >
<#list pks as prop>
        ${prop.name} = ${"#"}{${prop.alias},jdbcType=${prop.jdbcType}},
</#list>
    </trim>
  </select>
</#if>
<#if (pks?size>0)>
  <delete id="deleteByPrimaryKey" parameterType="map" >
    delete from ${config.tableName}
    where
    <trim prefix="(" suffix=")" suffixOverrides="," >
<#list pks as prop>
        ${prop.name} = ${"#"}{${prop.alias},jdbcType=${prop.jdbcType}},
</#list>
    </trim>
  </delete>
</#if>
  <delete id="deleteByExample" parameterType="${projectConfig.beanPackage}.${config.model}.bean.po.gen.${config.objectName}Example" >
    delete from ${config.tableName}
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="${projectConfig.beanPackage}.${config.model}.bean.po.gen.${config.objectName}" >
    insert into ${config.tableName}
    <trim prefix="(" suffix=")" suffixOverrides="," >
<#list pks as prop>
        ${prop.name},
</#list>
<#list columns as prop>
        ${prop.name},
</#list>
    </trim>
    values
    <trim prefix="(" suffix=")" suffixOverrides="," >
<#list pks as prop>
        ${"#"}{${prop.alias},jdbcType=${prop.jdbcType}},
</#list>
<#list columns as prop>
        ${"#"}{${prop.alias},jdbcType=${prop.jdbcType}},
</#list>
    </trim>
  </insert>
  <insert id="insertSelective" parameterType="${projectConfig.beanPackage}.${config.model}.bean.po.gen.${config.objectName}" <#if config.keyGenProperty??> useGeneratedKeys="true" keyProperty="${config.keyGenProperty}" </#if>>
    insert into ${config.tableName}
        <trim prefix="(" suffix=")" suffixOverrides="," >
<#list pks as prop>
      <if test="${prop.alias} != null" >
        ${prop.name},
      </if>
</#list>
<#list columns as prop>
      <if test="${prop.alias} != null" >
        ${prop.name},
      </if>
</#list>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
<#list pks as prop>
      <if test="${prop.alias} != null" >
        ${"#"}{${prop.alias},jdbcType=${prop.jdbcType}},
      </if>
</#list>
<#list columns as prop>
      <if test="${prop.alias} != null" >
        ${"#"}{${prop.alias},jdbcType=${prop.jdbcType}},
      </if>
</#list>
    </trim>
  </insert>
  <select id="countByExample" parameterType="${projectConfig.beanPackage}.${config.model}.bean.po.gen.${config.objectName}Example" resultType="java.lang.Integer" >
    select count(*) from ${config.tableName}
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update ${config.tableName}
    <set >
<#list pks as prop>
      <if test="record.${prop.alias} != null" >
        ${prop.name} = ${"#"}{record.${prop.alias},jdbcType=${prop.jdbcType}},
      </if>
</#list>
<#list columns as prop>
      <if test="record.${prop.alias} != null" >
        ${prop.name} = ${"#"}{record.${prop.alias},jdbcType=${prop.jdbcType}},
      </if>
</#list>
    </set>
    <if test="example != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  
  <update id="updateByExample" parameterType="map" >
    update ${config.tableName}
    <set >
<#list pks as prop>
      	${prop.name} = ${"#"}{record.${prop.alias},jdbcType=${prop.jdbcType}},
</#list>
<#list columns as prop>
        ${prop.name} = ${"#"}{record.${prop.alias},jdbcType=${prop.jdbcType}},
</#list>
    </set>
    <if test="example != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
<#if (pks?size>0)>
  <update id="updateByPrimaryKeySelective" parameterType="${projectConfig.beanPackage}.${config.model}.bean.po.gen.${config.objectName}" >
    update ${config.tableName}
    <set >
<#list columns as prop>
      <if test="${prop.alias} != null" >
        ${prop.name} = ${"#"}{${prop.alias},jdbcType=${prop.jdbcType}},
      </if>
</#list>
    </set>
    where
    <trim prefix="(" suffix=")" suffixOverrides="," >
<#list pks as prop>
        ${prop.name} = ${"#"}{${prop.alias},jdbcType=${prop.jdbcType}},
</#list>
    </trim>
  </update>
</#if>
<#if (pks?size>0)>
  <update id="updateByPrimaryKey" parameterType="${projectConfig.beanPackage}.${config.model}.bean.po.gen.${config.objectName}" >
    update ${config.tableName}
        <set >
<#list columns as prop>
        ${prop.name} = ${"#"}{${prop.alias},jdbcType=${prop.jdbcType}},
</#list>
    </set>
    where
    <trim prefix="(" suffix=")" suffixOverrides="," >
<#list pks as prop>
        ${prop.name} = ${"#"}{${prop.alias},jdbcType=${prop.jdbcType}},
</#list>
    </trim>
  </update>
</#if>
</mapper>